.htaccess

.htaccess - how to remove repeated words in url?

淺唱寂寞╮ 提交于 2020-01-02 14:13:05
问题 What is the regex in .htaccess to go from those urls: example.com/hello-world-world example.com/hello-world-hello to this one: example.com/hello-world using RewriteCond like this: RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^REGEX$ RewriteRule . %1 [R=301,L] 回答1: Removing all the duplicate words from slug is pretty tricky to be done in mod_rewrite only but here is a lookahead based regex rule than you can use: RewriteEngine On RewriteCond %{REQUEST_URI} ^/((?:[^-]*-)*)([^-

How to replace robots.txt with .htaccess

空扰寡人 提交于 2020-01-02 10:09:18
问题 I have a small situation where i have to remove my robots.txt file because i don't want and robots crawlers to get the links. Also i want them to be accessible by the user and i don't want them to be cached by the search engines. Also i cannot add any user authentications for various reasons. So i am thinking about using mod-rewrite to disable search engine crawlers from crawling it while allowing all others to do it. The logic i am trying to implement is write a condition to check if the

htaccess to strip www and force SSL

一个人想着一个人 提交于 2020-01-02 09:55:42
问题 I have what I believe to be a rather well crafted .htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE] RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] This says to me "strip the www. off the url and force https." And it works fine except for those people who happen to type in https://www.somedomain.com/. Those people are presented with a warning that there is a problem with the site

Redirect subdomain request to subdirectory + https (using .htaccess)

∥☆過路亽.° 提交于 2020-01-02 09:10:15
问题 I've got some issues with a .htaccess that I just can't get to work. Hope someone could solve this one. I have a SSL certificate on the www.-domain on an Apache server. I want all http://subdomain.domain.com requests on a specified list of subdomains to redirect to https://www.domain.com/subdomain . The second problem is I don't have a wildcard certificate that works on non-www. requests, requests to https://subdomain.domain.com will result in an "Untrusted Connection" alert. So this also has

Opencart .htaccess issue

戏子无情 提交于 2020-01-02 08:58:30
问题 I'm having similar problem My url is like name.domain.com/subdoamin/store/index.php?... and my htaccess file is : Options +FollowSymlinks # Prevent Directoy listing Options -Indexes # Prevent Direct Access to files <FilesMatch "\.tpl"> Order deny,allow Deny from all </FilesMatch> #<FilesMatch "\.ini"> #Order deny,allow #Deny from all #</files> # SEO URL Settings RewriteEngine On RewriteBase /store/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^(.*)\?*$

Opencart .htaccess issue

岁酱吖の 提交于 2020-01-02 08:58:15
问题 I'm having similar problem My url is like name.domain.com/subdoamin/store/index.php?... and my htaccess file is : Options +FollowSymlinks # Prevent Directoy listing Options -Indexes # Prevent Direct Access to files <FilesMatch "\.tpl"> Order deny,allow Deny from all </FilesMatch> #<FilesMatch "\.ini"> #Order deny,allow #Deny from all #</files> # SEO URL Settings RewriteEngine On RewriteBase /store/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^(.*)\?*$

What does RewriteRule ^(.*)/$ ?path=$1 [QSA,L] mean in my .htaccess?

浪尽此生 提交于 2020-01-02 08:52:11
问题 I need to create rewrite in nginx as is done in my .htaccess and there are some lines which I don't completely understand. DirectoryIndex index.php RewriteEngine on RewriteCond % !-f RewriteRule ^(.*)/$ ?path=$1 [QSA,L] Can someone explain it to me? 回答1: RewriteCond % !-f seems incorrect rule condition and is always evaluating to true. This rule: RewriteRule ^(.*)/$ ?path=$1 [QSA,L] Is matching any URI with trailing slash and internally rewriting to /?path=uri-without-slash So for ex: an URI

Mod Rewrite, pass parameters from URL1 to URL2

六眼飞鱼酱① 提交于 2020-01-02 08:23:13
问题 I'm trying to rewrite the following URL test.php?par1=foo&par2=bar Into... newtest.php?hidden_par=blah&par1=foo&par2=bar I have this rule, that does not work: RewriteRule ^test.php\??(.*?)$ newtest.php?hiden_par=blah&$1 [L] Could this be done using RewriteCond or something else? (say, could this be done ?), thanks in advance. 回答1: You probably want something like the QSA ("query string append") flag, which causes the remainder of the query string to be properly appended onto the end of the

How to remove empty parameter or parameters anywhere in URL by .htaccess?

感情迁移 提交于 2020-01-02 07:43:15
问题 Empty parameters that I mean can be anywhere in URL each time different place, each time with different name, each time on different php page e.g : http://www.example.com/AnyPHPpageHere.php?parameter1=7&parameter2=&parameter3=blue&parameter4= to the form: http://www.example.com/AnyPHPpageHere.php?parameter1=7&parameter3=blue So how to do it via .htaccess? 回答1: You can use this URL to remove any one or more empty parameters from anywhere in URLs: RewriteEngine On RewriteCond %{QUERY_STRING} ^(

PHP $_GET var with urlencode and “&” bug

穿精又带淫゛_ 提交于 2020-01-02 07:18:09
问题 In my code, I create a link like this: $link = 'http://www.mydomain.com/'.urlencode($str).'/1'; I use url-rewriting and the rule in my htaccess file looks like this: rewriteRule ^(.+)/(.*)$ index.php?var1=$1&var2=$2 [NC,L] This code is working fine for almost every strings. But sometimes, the string to encode contains "&". The urlencode function encodes it corectly, but when I read the $_GET array in php, it looks like this (with $str = 'substring1&substring2'): 'var1' => 'substring1'