Search code examples
.htaccesshttp-redirectmod-rewriteurl-rewritingfriendly-url

Remove subfolder with URL Rewriting not working


I'm trying to rewrite the URL's contained looks like: https://mywebsite/FOF/news/page/page1.php

I think it's not very aesthetic as url and I would like it to look more like this:

https://mywebsite/customPage

This request is very specific for url https://mywebsite/FOF/news/page/page1.php

My code works, the urls of the https://mywebsite/FOF directory are rewrite, but on the other hand the main url of my site and the urls of the other files are no longer accessible, I do not understand where my error comes from, if someone can help me

Options +FollowSymlinks
RewriteBase /    
RewriteEngine on    
RewriteRule ^page1$ page1.php    
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+FOF/news/page/([^\s]+) [NC]    
RewriteRule ^%1 [R=301,L]   
RewriteCond %{REQUEST_FILENAME} !-f   
RewriteRule (?!^FOF/news/page/)^(.*)$ /FOF/news/page/$1 [L?NC]

Solution

  • with your shown samples, could you please try following Rules in your htacces file. Make sure your htaccess file is present aside with FOF folder(not inside it).

    Please make sure to clear your browser cache before testing your URLs.

    ##Enabling FollowSymlinks and disabling MultiViews options here.
    Options +FollowSymlinks -MultiViews
    ##Setting rewrite base to / here.
    RewriteBase /
    RewriteEngine on
    ##Rewriting for page1 uri here.
    RewriteRule ^page1$ page1.php    
    ##External redirect rules here.
    RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\s [NC]
    RewriteRule ^ /customPage? [R=301,L]
    
    ##Internal rewrite rules here...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^customPage/?$ FOF/news/page/page1.php [L,NC]