0

Go easy on me I'm new to making changes to .htaccess files. I have the following .htaccess file:

RewriteEngine On RewriteBase / # Exclude rewriting for specific file types and existing files RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif)$ # Redirections RewriteRule ^search$ search.php [L] RewriteRule ^our-story$ our-story.html [L] RewriteRule ^blog$ blog.php RewriteRule ^contact$ contact.html RewriteRule ^faq$ faq.html RewriteRule ^pricing$ pricing.html RewriteRule ^register$ register.php RewriteRule ^login$ login.php RewriteRule ^dashboard$ dashboard.php RewriteRule ^404$ 404.html # 404 Page ErrorDocument 404 /404.html 

The questions and problems are as followed.

  1. The 404 doesn't work when the 404 isn't in home directory example https://link.com/fakelink will go to 404 correctly but https://link.com/direct/fakelink will not go to 404 correctly.
  2. Is there a better way to handle Redirections without having to manually do each one like I am currently doing?

Another thing I don't know how to do I have a php file that looks like (https://link.com/list.php?url=city-location/listing-name) I want it to rewrite to https://link.com/city-location/listing-name how can I go about doing this?

All help is appreciate!

4
  • "Another thing" - for that, I'd like to refer you to Reference: mod_rewrite, URL rewriting and "pretty links" explained - read up on a bit of the basics, and then make an attempt. Commented Nov 15, 2023 at 7:04
  • 2. you can combine multiple of those rules into one, RewriteRule ^(search|blog|...)$ $1.php [L], and the same for the .html files. Commented Nov 15, 2023 at 7:06
  • RewriteConds affect only the immediately following rule, so the way they are used here makes rather little sense. They affect the ^search$ rule only, and that does neither match an existing file, nor does it have any of those suffixes. Commented Nov 15, 2023 at 7:07
  • 1. not sure what causes that, but I would suspect it probably has to do with that last rule, RewriteRule ^404$ 404.html. Try and remove that. (There should be no real need to have a "pretty" URL for your error document, no one is expected to deliberately request /404 in the first place, right?) Commented Nov 15, 2023 at 7:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.