ceskyDJ

Sitemap redirect for OOP or MVC in PHP through htaccess

Feb 7th, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # First version
  2. # mod_rewrite is required
  3. <IfModule mod_rewrite.c>
  4.   # Start rewrite engine and set the root path
  5.   RewriteEngine on
  6.   RewriteBase /
  7.  
  8.   # Permanent move /sitemap.xml --> /sitemap
  9.   RewriteCond %{REQUEST_URI} ^/sitemap\.xml$
  10.   RewriteRule ^sitemap\.xml$ /sitemap [R=301,L]
  11.  
  12.   # Redirect all requests to index.php (exept valid addresses)
  13.   RewriteCond %{REQUEST_FILENAME} !-f
  14.   RewriteCond %{REQUEST_FILENAME} !-d
  15.   RewriteRule !\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$ index.php [L]
  16. </IfModule>
  17.  
  18.  
  19. # Second version
  20. # mod_rewrite is required
  21. <IfModule mod_rewrite.c>
  22.   # Start rewrite engine and set the root path
  23.   RewriteEngine on
  24.   RewriteBase /
  25.  
  26.   # Redirect all requests to index.php (exept valid addresses)
  27.   RewriteCond %{REQUEST_FILENAME} !-f
  28.   RewriteCond %{REQUEST_FILENAME} !-d
  29.   # Exeption - permanent move sitemap.xml --> /sitemap
  30.   RewriteRule ^sitemap\.xml$ /sitemap [R=301,L]
  31.   RewriteRule !\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$ index.php [L]
  32. </IfModule>
Advertisement