How do I include space in a RewriteRule?
I need to update my .htaccess file for url rewriting. Even this post didn't help. I need to distract myself like this, but it won't work!
First requirement
(Alphabet only - case insensitive - accepts space)
domain.com/Acco unting > domain.com/edit.jsp?kazem=Acco unting&oto=1&sab= domain.com/acco unting > domain.com/edit.jsp?kazem=acco unting&oto=1&sab= domain.com/Accounting > domain.com/edit.jsp?kazem=Accounting&oto=1&sab= domain.com/accounting > domain.com/edit.jsp?kazem=accounting&oto=1&sab=
Second requirement
(The first part of the alphabet only, take the space - the alphabet and the number of the second part, take the space)
domain.com/Accounting/city 2222 > domain.com/edit.jsp?kazem=Accounting&oto=1&sab=city 2222 domain.com/Accou nting/city 2222 > domain.com/edit.jsp?kazem=Accou nting&oto=1&sab=city 2222
My .htaccess looks like this
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
#Options +FollowSymLinks
#IndexIgnore */*
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule ^(.*)/(.*[0-9]+)$ /edit.jsp?kazem$1&oto=1&sab=$2 [L]
</ifModule>
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
#RewriteRule ^(.[a-zA-Z]+)$ /edit.jsp?kazem=$1&oto=1&sab= [L]
RewriteRule "^([a-z]+( [a-z]+)?)/?$" /edit.jsp?kazem=$1&oto=1&sab= [L]
</ifModule>
IndexIgnore *
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
# Header set Access-Control-Allow-Credentials true
Header add Access-Control-Allow-Headers "*,origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "GET, POST, DELETE, OPTIONS"
</IfModule>
DirectoryIndex index.html index.php
+3
source to share
2 answers
This rule should work for you:
RewriteEngine On
RewriteBase /
RewriteRule "^([a-z]+( [a-z]+)?)/?$" edit.jsp?name=$1 [L,QSA,NC]
- Do not use
http://
in the target URI, otherwise it will become an external redirect withR=302
- Quote pattern when using space
Complete .htaccess:
IndexIgnore *
DirectoryIndex index.html index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule ^([^/]+)/(\d+)/?$ edit.jsp?kazem$1&oto=1&sab=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule "^(\S+(?: \S+)*)/?$" edit.jsp?kazem=$1&oto=1&sab= [L,QSA]
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
# Header set Access-Control-Allow-Credentials true
Header add Access-Control-Allow-Headers "*,origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "GET, POST, DELETE, OPTIONS"
</IfModule>
+3
source to share
You want to use the NE
RewriteRule flag :
RewriteRule ^([a-z\s]+)$ http://example.com/edit.jsp?name=$1 [NC,NE,L]
+1
source to share