Hey!

I have the following code for htaccess that directs /page/ to /page.php etc

RewriteEngine On  

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

#RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^([a-z0-9\-]+)/?$ $1.php [NC,L,QSA]

However, I want to also add /admin/page/ that will rewrite to /admin/page.php
How might I go about adding this ability.

Thanks
Dan

So the line RewriteRule ^([a-z0-9\-]+)/?$ $1.php [NC,L,QSA] says to rewrite anything/ to anything.php

Rules execute in order, so above that line you can add a line that simply says:

RewriteRule ^admin/page/$ admin/page.php [L]

I might have a typo but that should be what you're looking for.

Thanks for your quick reply!

I would need this to rewrite /admin/anything/ to /admin/anything.php

So anything can be put after admin and load that page, would the above do this?
Thanks

You would need to use regular expressions the way you are doing with the other one. But I’m in bed on my phone so I can’t type it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.