0

This question may be duplicated but I search a lot and can't find an answer. So I'm using htaccess file to Rewrite and I want to show the same page using URLs : http://localhost/assoc/about and http://localhost/assoc/about/ .

I call page contents by " include_once " and pages are located in directory /www/assoc/astc/ . When I tape for example http://localhost/assoc/about it works but with the training slash, it redirects to 404 page.

Here is my htaccess. Thanks.

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]

RewriteRule ([a-z]+)$ astc/accueil.php?page=$1 [L]

RewriteRule ^/(.*)$ astc/accueil.php?page=$1 [R=301,L]

RewriteRule ([a-z]+)/([A-Za-z0-9_]+)$ astc/accueil.php?page=$1&id=$2 [L]

RewriteRule ^/(.*)$ astc/accueil.php?page=$1&id=$2 [R=301,L]

ErrorDocument 404 http://localhost/assoc/page-non-trouvee
arshie92
  • 73
  • 1
  • 1
  • 10
  • Is this .htaccess placed in `/www/assoc/astc/ ` directory? – anubhava Aug 16 '16 at 13:39
  • Your `.htaccess` file is very badly formed, and makes very little sense whatsoever. Leading slashes are not supported in `.htaccess`, and the condition at the top will only apply to the first rule, and nothing after that. Also, the last rule only has one parameter `(.*)`, but is trying to get data for two (`$1` and `$2`). I highly recommend that you read through the documentation and various guides available, otherwise you are going to continue having problems without learning how things really work. – Mike Rockétt Aug 16 '16 at 14:02
  • I will read through the documentaion so. Thanks. – arshie92 Aug 16 '16 at 15:34

3 Answers3

1

There are few problems. This line

RewriteRule ^/(.*)$ astc/accueil.php?page=$1 [R=301,L]

redirects all the requests into astc/accueil.php?page=

I also suggest to remap instead of redirect your requests

This ^/(.*)$ regex catches all the requests so it is impossible for the remaining rewrite rules being evaluated.

Try adding rewrite log to debug your regex

Community
  • 1
  • 1
freedev
  • 25,946
  • 8
  • 108
  • 125
  • I will check that and try to resolve the issue. I haven't read enought documentation about rewriting so, I missed a lot of things. I will reback. Thank you. – arshie92 Aug 16 '16 at 15:40
0

Unless you already have it, try adding the following line to your htaccess

DirectorySlash On
  • I tend to use a virgin htacces to test a particular item. You have plenty of redir stuff sitting there, which may interfere at some point. If it doesn't break your host, try the slash thing with a clean htaccess first, then add one item a time to make sure you know where it gets buggy. Good luck tweaking. –  Aug 16 '16 at 12:50
  • I continue to find a way. Thanks. – arshie92 Aug 16 '16 at 15:40
0

So finally it's working with this content :

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]

RewriteRule ([a-z]+)(/?)$ astc/accueil.php?page=$1 [L]

RewriteRule ([a-z]+)/([A-Za-z0-9_]+)(/?)$ astc/accueil.php?page=$1&id=$2 [L]

ErrorDocument 404 http://localhost/assoc/page-non-trouvee

Thanks to all of you.

arshie92
  • 73
  • 1
  • 1
  • 10