logo
down
shadow

Why are these mod_rewrite rules not working?


Why are these mod_rewrite rules not working?

By : stone.sw
Date : November 18 2020, 01:01 AM
should help you out Rules are behaving because RewriteCond is only applied to very next RewriteRule. Due to this your last RewriteRule is running without conditions and hence running twice by mod_rewrite loop.
Use this code to fix it:
code :
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.+?)/(\d+?)/?$ index.php?cmd=$1&num=$2 [L]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.+?)/?$ index.php?cmd=$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine On

  # skips files and directories from rewrite rules
  RewriteCond %{REQUEST_FILENAME} -d [OR]
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^ - [L]

  RewriteRule ^(.+?)/(\d+?)/?$ index.php?cmd=$1&num=$2 [L]

  RewriteRule ^(.+?)/?$ index.php?cmd=$1 [L]
</IfModule> 


Share : facebook icon twitter icon
mod_rewrite rules aren't working

mod_rewrite rules aren't working


By : paulo
Date : March 29 2020, 07:55 AM
Any of those help In the .htaccess you posted above, there is no RewriteRule immediately following these rules:
code :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?mythofechelon\.co.uk)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
# Strip www. from domain name 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Send requests for non-existent files and directories to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^home/(.*)$ /main/pages/index.php?$1 [L]
BrowserMatchNoCase Anarchie bad_bot
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^!home/(.*)$ /main/pages/index.php?404 [L]
mod_rewrite rules not working as expected

mod_rewrite rules not working as expected


By : sri subramaniam
Date : March 29 2020, 07:55 AM
wish helps you Turns out my rules do work as expected. I was previously trying using these rules in apache.conf. Moving it to the sites "VirtualDirectory" tag seemed to do the trick
Why are some of my mod_rewrite rules not working?

Why are some of my mod_rewrite rules not working?


By : Vladimir Alfaro
Date : March 29 2020, 07:55 AM
this one helps. I don't know why the following fixed my issue, but it did. Following this question:
mod_rewrite not behaving nicely
Simple mod_rewrite rules not working

Simple mod_rewrite rules not working


By : Md Noor
Date : March 29 2020, 07:55 AM
wish of those help If you have mod rewrite rules in vhost/server config, it requires a / as part of the pattern. The second rule doesn't work because you want $1, and not 1$:
code :
RewriteRule ^/([^.]+)$ /$1.html [L]
mod_rewrite rules in httpd.conf not working

mod_rewrite rules in httpd.conf not working


By : enemene meneene
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Inside the http servers host configuration you need to keep the leading slash in path notations, a RewriteBase does not make any sense and the rules need to be placed outside some or section. You have to remove the leading slash in the RewriteCond testing the %{HTTP_HOST}, but you have to escape the dot characters in there. It seems some current versions of the apache http server do not always define the %{HTTPS} variable as claimed in the documentation, you can test for the port instead:
code :
<VirtualHost *:443>
  ServerName example.com
  ServerAlias www.example.com
  ServerAdmin webmaster@example.com
  # ...
  ServerSignature off
  DocumentRoot "/home/shopmobilephones/public_html"

  RewriteEngine On
  # HTTP > HTTPS & www host
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^ https://shopmobilephones.co.uk%{REQUEST_URI} [R=301]
  RewriteCond %{HTTP_HOST} ^www\.shopmobilephones\.co\.uk$
  RewriteRule ^ https://shopmobilephones.co.uk%{REQUEST_URI} [R=301]
  RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
  RewriteRule .* ? [F,L]

  RewriteRule ^/mobiles/deals/cash-back /cashback.php [L]
  RewriteRule ^/mobiles/deals/cheap-mobile-phones /cheapmobilephones.php [L]
  RewriteRule ^/mobiles/deals/clearance-deals /clearance.php [L]
  RewriteRule ^/mobiles/deals/contracts /contractphones.php [L]
  RewriteRule ^/mobiles/deals/12-months-free-line-rental /12month.php [L]
  RewriteRule ^/mobiles/deals/top-deals /dailydeals.php [L]
  RewriteRule ^/mobiles/deals/free-phones /freephones.php [L]
  RewriteRule ^/mobiles/deals/new-mobile-phones /ladeals.php [L]
  RewriteRule ^/mobiles/deals/sim-free-phones /simfree.php [L]
  RewriteRule ^/mobiles/colours/(.*) /colours.php?colour=$1 [L]
  RewriteRule ^/mobiles/(.*)/contract-deals /dealsnew.php?slug=$1&deal-type=1&device-type=Phone&network=all [L]
  RewriteRule ^/mobiles/(.*)/upgrades /dealsnew.php?slug=$1&deal-type=2&device-type=Phone&network=all [L]
  RewriteRule ^/mobiles/(.*)/contract-deals/(.*) /dealsnew.php?slug=$1&deal-type=1&device-type=Phone&NETWORK=$2 [L]

  <Directory "/home/shopmobilephones/public_html">
    # .....
  </Directory>
</VirtualHost>
Related Posts Related Posts :
  • https with url rewriting
  • Trying to get Websockify/noVNC to work through a reverse proxy
  • .htaccess rewrite parameters not passing to target page
  • my htaccess does not affect the url
  • Trying to apply mod rewrite rule for e.g. css/style.123456.css -> css/style.min.css
  • Joomla 301 redirect in .htaccess returns 404 error
  • Pass ID to another URL
  • apache2 external disk permissions
  • apache mod_rewrite user URLs to index.php
  • Redirect from subfolder to main domain with different port
  • Which ErrorDocument request will take precedence?
  • How make apache redirect the user to some page when the requested page is not existing
  • warn NameVirtualHost *:443 has no VirtualHosts
  • Remove specific slug in with htaccess
  • Relatively where does solr.data.dir in solrconfig.xml points to?
  • Redirecting HTTP to HTTPS correctly in Question2Answer script
  • htaccess mod_rewrite: Simplifying URL
  • .htaccess Adding a trailing slash to requested files
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org