1

I want to redirect this php url to the folder.

I always used the settings below. But since the update of apache to 2.4 it doesnt work anymore.

Goal: example.com/about.php?sub=about or example.com/about.php?sub= should be seen in the browser as example.com/about/

I use the following settings.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(example.com)(:80)? [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301] 

RewriteRule ^about/$ about.php$1 [L]
RewriteRule ^about/([A-Za-z0-9-]+)$ about.php?sub=$1 [L]

This is what I am using now...

3
  • [A-Za-z0-9-]+ can be written as \w+ Commented Oct 2, 2013 at 13:54
  • 1
    @hjpotter92 Not so; \w includes underscores. Commented Oct 2, 2013 at 14:10
  • @theftprevention Ah! It doesn't in lua and hence, my suggestion. Commented Oct 2, 2013 at 14:14

1 Answer 1

1

I don't see any rule in your code that is making /about.php?sub= to /about.

Try this code:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(about)\.php(\?sub=[^\s&]*)?\s [NC]
RewriteRule ^ /%1? [R=301,L]

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

# Add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R]
Sign up to request clarification or add additional context in comments.

14 Comments

Is -Multiviews a must have in the .htaccess? Just curious... But I still have the same problem I only get the text in the browser with sub= or sub=about the subpage is a single php file with text only. With the link www.example.com/about/about I see the complete website with the text inside the layout. But www.example.com/about/ gives the text without any body or layout.
/about.php?sub= or /about.php?sub=about to /about/ is the goal.
First thing that you need to explain your problem with more clarity. What exactly is your URL that worked earlier before these rules? Was http://site.com/about.php?sub=about a working URL? If you enter ` /about.php?sub=about` it should become /about but whether correct content is displayed or not depends on image, css, js inclusions.
Yes, now /about.php?sub=about redirects to /about/ and /about.php also to /about/. First it didn't. Before about.php showed the text inside the body and now with the redirect to /about/ it doesn't.
The url that worked before was example.com/about/ and gave the complete website and put the text from the sub=about into the website with a php include function. Since the apache update I only see plain text without layout when I go to example.com/about/ I hope this brings some clarity.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.